package com.aivin.service.impl;

import com.aivin.dao.IPicDao;
import com.aivin.dao.ITbUserDao;
import com.aivin.entity.FollowUserBean;
import com.aivin.entity.TbPic;
import com.aivin.entity.TbUser;
import com.aivin.entity.TbUserV1;
import com.aivin.service.PicService;
import com.aivin.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * Created by Administrator on 2016/8/22.
 */
@Service
public class UserServiceImpl implements UserService{



    @Autowired
    private ITbUserDao  userDao;
    public List<TbUser> queryAllUserFy(  int offset  ,   int limit){

        return  userDao.queryAllUserFy( offset ,limit) ;

    }


    @Deprecated
    public TbUser  getUserInfoByUserId(int userId){
        TbUser bean =  userDao.getUserInfoByUserId(userId);
        return bean ;
    }

    public TbUserV1  getUserInfoByUserIdV1(int userId){
        TbUserV1  bean =  userDao.getUserInfoByUserIdV1(userId);
        return bean ;
    }

    public int getfollowdStateByUser( int followdUserId   ,  int userId  ){

        FollowUserBean bean  = userDao.getfollowdStateByUser(followdUserId ,userId);
        int state  =   bean==null ?  -1  : bean.getState() ;
        return state ;
    }

    public int addFollowdStateByUserId( FollowUserBean bean) {
        int state  = userDao.addFollowdStateByUserId(bean) ;
        return  state  ;//
    }


    public int  setFollowedStateByUserId(@PathVariable int userFollowedId   ,@PathVariable int userId  ,@PathVariable int followedState ){
        int state  = userDao.setFollowedStateByUserId(userFollowedId ,userId , followedState);
        return  state  ;//
    }

    /**用户是否存在*/

    public int  checkUserExist( @PathVariable String userName   ){
        List<TbUserV1>   list = userDao.checkUserExist(userName  );

        if(list==null){
            System.out.println("list== null" );
        }else{
            System.out.println("list== " +list.size() );
        }


        int  userId = ( list==null||list.size()==0)   ? -1 :  10000 ;
        return userId;
    }

    /**密码登陆*/
    public TbUserV1  loginByPwd(@PathVariable String userName   ,@PathVariable String  userPwd  ) {
        TbUserV1 bean =  userDao.loginByPwd(userName ,  userPwd);
        return  bean ;
    }

    /**用户账号注册**/
    public String  regByPwd(TbUserV1 bean){
        //int state  =
        userDao.regByPwd( bean) ;
        int  state =bean.getId() ;
        System.out.println("用户注册 ="+bean.getId());
        return  String.valueOf(state)  ;
    }

    /**用户是否存在-第三方登录*/
    public int   checkUserExistByThird(@PathVariable String uuid  ,@PathVariable String platform) {
        List<TbUserV1>   list = userDao.checkUserExistByThird(uuid   , platform  );

        int  userId = ( list==null||list.size()==0)   ? -1 :  list.get(0).getId() ;
        return userId;
    }

    public List<FollowUserBean>  getfollowdListByUserId( int userId   ,  int offset , int limit ) {
        List<FollowUserBean> list =  userDao.getfollowdListByUserId(userId    , offset ,  limit );
        return  list;
    }

    /**更新验证码**/
    public int  updataVtCodeAndTime( int userId ,String vtCode ,String reqTime ){
        return  userDao.updataVtCodeAndTime(userId ,vtCode ,reqTime);
    }

    /**更新用户头像**/
    public  int  upDateUserImgUrl(    int userId , String imgUrl   ) {
        return   userDao.upDateUserImgUrl(userId ,imgUrl);
    }

    /**更新用户密码*/
    public  int  upDateUserPwd(     int userId ,   String userPwd   ) {
        return   userDao.upDateUserPwd(userId ,userPwd);
    }

    /** 绑定、更新用户 电话号码*/
    public  int  bindOrUpDateUserTel(int userId, String userTel){
        return    userDao.bindOrUpDateUserTel(userId ,userTel);
    }

    /**更新用户昵称*/
    public  int  upDateUserNickeName(     int userId ,   String nickName   ) {
        return   userDao.upDateUserNickeName(userId ,nickName);
    }

}
